﻿////////////////////////////////////////////////////////////////////////////////
//
//  GiantJadder@gmail.com
//	This class is designed to generate dynamic sectors.
//
////////////////////////////////////////////////////////////////////////////////
package com.zhangjunkai.display
{
	import flash.display.Sprite;
	import flash.display.Graphics;

	public class Sector extends Sprite
	{

		private var innerRadius:Number;
		private var outterRadius:Number;
		private var angle:Number;
		private var startXAngle:Number;
		private var quality:int;
		private var color:uint;
		private var sectorAlpha:Number;

		private var n:int;
		private var smallAngle:Number;

		private var g:Graphics;

		public function reDraw(_innerRadius:Number, _outterRadius:Number, _angle:Number, _startXAngle:Number, _color:uint, _alpha:Number, _quality:int // from 0 ~ 4;
			):void
		{
			innerRadius=_innerRadius;
			outterRadius=_outterRadius;
			angle=_angle;
			startXAngle=_startXAngle;
			quality=_quality;
			color=_color;
			sectorAlpha=_alpha;

			g=graphics;
			g.clear();

			n=20 * (quality + 1);

			smallAngle=angle / n;

			var i:int=0;

			g.beginFill(color, sectorAlpha);

			g.moveTo(outterRadius * Math.cos(startXAngle), -outterRadius * Math.sin(startXAngle));
			for (i=1; i <= n; i++)
			{
				g.lineTo(outterRadius * Math.cos(startXAngle + i * smallAngle), -outterRadius * Math.sin(startXAngle + i * smallAngle));
			}

			g.lineTo(innerRadius * Math.cos(startXAngle + angle), -innerRadius * Math.sin(startXAngle + angle));
			for (i=1; i <= n; i++)
			{
				g.lineTo(innerRadius * Math.cos(startXAngle + angle - i * smallAngle), -innerRadius * Math.sin(startXAngle + angle - i * smallAngle));
			}
			g.endFill();
		}
	}
}


